<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


class Message extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("UsersMessage");
        parent::__construct();
    }


    public function index(){
        //消息销售

        $where['a.status'] =0;

        //时间的处理
        $res = $this->model->message_page($where);


        $this->model->where(['status'=>0])->update(['status'=>1]);

        return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }



    public function save(){
        //消息销售

        $where = [];
        //时间的处理
        $res = $this->model->message_page($where);

        return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }

    public function imessage(){
        $result = $this->model->where(['id'=>$this->id])->find();
        if($result['is_read_status']){
            return failJson("failok");
        }
        $this->model->where(['id'=>$this->id])->update(['is_read_status'=>1]);
        return sucessJson("ok");
    }

    //消息
    public function messagenum(){
        $agents_ids = w_g("agents_ids");//ID列表
        //where('a.agent_id',"in",$agents_ids);
        if($agents_ids!='all'){
            $count = $this->model->alias("a")
                ->join("users u","u.id=a.user_id","left")
               ->where('u.agent_id',"in",$agents_ids)
                ->where("a.is_read_status",0)->count();
        }else{
            $count = $this->model->where("is_read_status",0)->count();
        }

        return sucessJson("ok",['count'=>$count]);
    }

    public function getread(){
        $where = [];
        $where['is_read_status'] = 0;
        //时间的处理
        $res = $this->model->message_page($where);
        return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }

    public function his(){
        $where = [];
        $where['is_read_status'] = 1;
        //时间的处理
        $res = $this->model->message_page($where);
        return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }

}
